{set:$ship=$this->data}
<div class="headbar clearfix">
	<div class="position">订单<span>></span><span>快递单管理</span><span>></span><span>{if:isset($ship['id'])}修改{else:}添加{/if}发货信息</span></div>
</div>
<form name="ModelForm" action="{url:/order/ship_info_update}" method="post"  onsubmit="return checkForm();">
<div class="content_box">
	<div class="content form_content">
		<table id="tab-1" class="form_table" name="table">
			<col width="150px" />
			<col />
			<tr>
				<th>发货点名称：</th><input type="hidden" name="sid" value="{$ship['id']}"/>
				<td><input class="normal" name="ship_name" type="text" pattern="required" value="{$ship['ship_name']}" alt="发货点名称"//><label>*发货地点名称</label></td>
			</tr>
			<tr>
				<th>发货人姓名：</th>
				<td><input class="normal" name="ship_user_name" type="text" pattern="required" value="{$ship['ship_user_name']}"  alt="发货人姓名"/><label>*发货人名称</label></td>
			</tr>
			<tr>
				<th>性别：</th>
				<td><label class='attr'><input type="radio" name="sex" value="1" checked/>先生</label><label class='attr'><input type="radio" name="sex" value="0" {if:$ship['sex']==0}checked='checked'{/if}/>女士</label><label>*</label></td>
			</tr>
			<tr>
				<th>地区：</th>
				<td>
				<select name="province" id="province" onchange="select_city(this.value,2);">
				{query: name=areas where=parent_id eq 0}<option value="{$item['area_id']}" {if:($ship['province']!='') && ($ship['province']==$item['area_id'])}selected{/if}>{$item['area_name']}</option>{/query}
				</select>
				<span id="selec2"></span><span id="selec3"></span><span>*</span>
				</td>
			</tr>
			<tr>
				<th>地址：</th>
				<td><input class="normal" name="address" type="text" pattern="required" value="{$ship['address']}"  alt="具体地址错误"/><label>*具体地址</label></td>
			</tr>
			<tr>
				<th>邮编：</th>
				<td><input class="normal" name="postcode" type="text" pattern="zip" value="{$ship['postcode']}"  alt="邮编错误"/><label>*邮政编码</label></td>
			</tr>
			<tr>
				<th>手机：</th>
				<td><input class="normal" name="mobile" type="text" pattern='mobi' value="{$ship['mobile']}"/><label>*手机号码</label></td>
			</tr>
			<tr>
				<th>电话：</th>
				<td><input class="normal" name="telphone" type="text" pattern="phone" empty alt="电话号码错误" value="{$ship['telphone']}" /></td>
			</tr>
			<tr>
				<th></th>
				<td><label><input type="checkbox" name="is_default" value="1" {if:$ship['is_default']==1}checked='checked'{/if}/>&nbsp;设置为默认地址</label></td>
			</tr>
		</table>
		<table class="form_table">
			<col width="150px" />
			<col />
			<tr>
				<td></td>
				<td><button class="submit" type="button" onclick = "checkForm()"><span>保 存</span></button></td>
			</tr>
		</table>
	</div>
</div>
</form>
<script>
var province_va = '';
var city_va = '';
var area_va = '';
{if:$ship['province']!=''}
province_va = {$ship['province']};
city_va = {$ship['city']};
area_va = {$ship['area']};
{/if}
if(city_va!='')
{
	select_city(province_va,2)
}
if(area_va!='')
{
	select_city(city_va,3)
}
function select_city(city,style)
{
	$.getJSON("{url:/block/area_child}",{aid:city}, function(json)
	{
		if(style==2)
		{
			var select_html = '<select name="city" id="city" onchange="select_city(this.value,3);">';
			select_html += '<option value="">请选择城市</option>';
			for( a in json)
			{
				if(json[a]['area_id']==city_va)
				{
					select_html +='<option value="'+json[a]['area_id']+'" selected>'+json[a]['area_name']+'</option>';
				}
				else
				{
					select_html +='<option value="'+json[a]['area_id']+'">'+json[a]['area_name']+'</option>';
				}
			}
			select_html +='</select>';
			if($("#selec3").text()=='')$("#selec3").hide();
			$("#selec"+style).html(select_html);
		}else
		{
			var select_html = '<select name="area" id="area">';
			select_html += '<option value="">请选择地区</option>';
			for( a in json)
			{
				if(json[a]['area_id']==area_va)
				{
					select_html +='<option value="'+json[a]['area_id']+'" selected>'+json[a]['area_name']+'</option>';
				}
				else
				{
					select_html +='<option value="'+json[a]['area_id']+'">'+json[a]['area_name']+'</option>';
				}
			}
			select_html +='</select>';
			$("#selec"+style).show();
			$("#selec"+style).html(select_html);
		}
	});
}
function checkForm()
{
	var city = $("#city").val();
	var area = $("#area").val();
	var isPass = true;
	if(city==undefined || city=='')
	{
		alert("请选择城市！");
		isPass = false;
		return false;
	}
	if(area==undefined || area=='')
	{
		alert('请选择地区');
		isPass = false;
		return false;
	}
	if(document.ModelForm.onsubmit()!=false && isPass)
		document.ModelForm.submit();
}

</script>
